package com.renu.jdependencyanalyser.freemarker.data;

import com.renu.jdependencyanalyser.data.ProjectDataCenter;
import com.renu.jdependencyanalyser.model.JarModel;
import com.renu.jdependencyanalyser.model.JarNode;

import java.util.*;

@Deprecated
public class DependencyJarData {

    private List<Integer> borderJarIds = new ArrayList<>();

    private Set<DependencyJarLabel> dependencyJarLabels = new HashSet<>();
    private List<DependencyRelation> dependencyRelationList = new ArrayList<>();

    private Map<String, JarModel> borderJarMap = ProjectDataCenter.projectInfo.getBorderJarMap();
    public DependencyJarData(Set<String> borderJars, JarNode jarNode) {
        findDependencyRelationList(borderJars, jarNode);

    }

    private void findDependencyRelationList(Set<String> borderJars, JarNode jarNode) {
        if (jarNode == null)
            return;
        if (borderJars.contains(jarNode.toJarSig())) {
            this.borderJarIds.add(jarNode.getId());
            JarModel jarModel = borderJarMap.get(jarNode.toJarSig());
            jarModel.setGroup(jarNode.getGroup());
            jarModel.setArtifact(jarNode.getArtifact());
            jarModel.setVersion(jarNode.getVersion());
        }
        this.dependencyJarLabels.add(new DependencyJarLabel(jarNode.getId(),jarNode.toString()));
        List<JarNode> children = jarNode.getChildren();
        for (JarNode child : children) {
            dependencyRelationList.add(new DependencyRelation(jarNode.getId(), child.getId()));
            findDependencyRelationList(borderJars, child);
        }

    }

    public List<Integer> getBorderJarIds() {
        return borderJarIds;
    }

    public Set<DependencyJarLabel> getDependencyJarLabels() {
        return dependencyJarLabels;
    }

    public List<DependencyRelation> getDependencyRelationList() {
        return dependencyRelationList;
    }
}
